#ifndef _CHANNEL_LOG_H
#define _CHANNEL_LOG_H

#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <Channel.h>
#include <map>
#include <malloc_align.h>
#include <csp_shared_types.h>
#include <ProcessComposition.h>

#define MAX_CH_LOG_SIZE 200000


using namespace std;

typedef struct log_item{
	int pid;
	char op;
	long chan_id;
	char size;
	bool put;
} log_item_t;


class ChannelLog
{
	public:
		~ChannelLog();
		Channel* GetChannel(long type, long id);
		static ChannelLog* Instance();
		void Increment(ProcessComposition* p, long channel_id, char op);
		void Decrement(ProcessComposition* p, long channel_id, char op);
		void Print();
	protected:
		ChannelLog();
		ChannelLog(const ChannelLog&);
		ChannelLog& operator= (const ChannelLog&);
	private:
		static ChannelLog* pinstance;
		log_item_t *log;
		pthread_mutex_t chan_log_lock;
		int i;
};

#endif
